package com.xca.znb.presenter;

import com.xca.znb.contact.UpdatePasswordContact;
import com.xca.znb.entity.User;
import com.xca.znb.model.imodel.IUpdatePassword;

public class UpdatePasswordPresenter {
    private UpdatePasswordContact updatePasswordContact ;
    private IUpdatePassword iUpdatePassword ;
    public UpdatePasswordPresenter(UpdatePasswordContact contact ,IUpdatePassword updatePassword){
        this.updatePasswordContact = contact ;
        this.iUpdatePassword = updatePassword ;}
    public void updatePassword(String phone , String oldPassword , String password){
        User user = iUpdatePassword.getUser(phone);
        if (!password.equals(user.getPassword()) && oldPassword.equals(user.getPassword())){
           iUpdatePassword.updateLoginPassword(phone,password);
        }
    }
    public boolean updateLoginSuccessful(String phone , String password){
        User user = iUpdatePassword.getUser(phone);
        if (password.equals(user.getPassword())){
            return  true;
        }else {
            return false ;
        }
    }

    public void updatePayPassword(String phone , String password){
        User user = iUpdatePassword.getUser(phone);
            if (!password.equals(user.getPay_password())){
                iUpdatePassword.updatePayPassword(phone, password);
        }

    }
    public boolean oldPawIsTure(String phone , String password){
        User user = iUpdatePassword.getUser(phone);
        if (password.equals(user.getPay_password())){
            return true ;
        }else {
            return false ;
        }
    }
    public boolean updatePaySuccessful(String phone , String password){
        User user = iUpdatePassword.getUser(phone);
        if (password.equals(user.getPay_password())){
            return  true;
        }else {
            return false ;
        }
    }

}
